import { BaseDTO } from './../../service-proxy/service-proxies';
import { Injectable } from '@angular/core';
import { ServiceProxy, UserInfoDTO } from '@shared/service-proxy/service-proxies';

@Injectable()
export class AppSessionService {

    private _user: UserInfoDTO;

    constructor(
        private _service: ServiceProxy
        // private _sessionService: SessionServiceProxy
    ) {
    }


    get user(): any {
        return this._user;
    }

    get userId(): number {
        return this.user ? this.user.id : null;
    }

    init(): Promise<boolean> {
        return new Promise<boolean>((resolve, reject) => {
            // this._user = null;
            // resolve(true);

            this._service.getCurrentLoginInformationsUsingGET().toPromise().then((result: BaseDTO) => {
                this._user = result.result;
                resolve(true);
            }, (err) => {
                reject(err);
            });
        });
    }
}
